package com.example.jrfwcwgl.controller;


import com.example.jrfwcwgl.entity.TCwClearing;
import com.example.jrfwcwgl.service.ITCwClearingService;
import com.github.pagehelper.PageInfo;
import com.org.dto.TCwClearingDto;
import com.org.vo.ResultEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 结算表 前端控制器
 * </p>
 *
 * @author 龚梦
 * @since 2021-04-08
 */
@RestController
@RequestMapping("/jrfwcwgl/TCwClearingController")
public class TCwClearingController {

    @Autowired
    private ITCwClearingService itCwClearingService;

    @RequestMapping("settlementManagement")
    public ResultEntity settlementManagement(@RequestBody TCwClearingDto tCwClearingDto){
        PageInfo<TCwClearing> pageInfo=itCwClearingService.selectTCwClearing(tCwClearingDto);
        return ResultEntity.ok("200","查询成功",pageInfo);
    }

    @RequestMapping("settlementManagementDispose")
    public ResultEntity confirmClearing(@RequestParam String ids) {
        TCwClearingDto tCwClearingDto = new TCwClearingDto();
        List<Long> list = null;
        if(ids!=null) {
            list = Arrays.asList(ids.split(",")).stream().map(s -> Long.parseLong(s.trim())).collect(Collectors.toList());
            tCwClearingDto.setClearingIdList(list);
            itCwClearingService.confirmClearing(tCwClearingDto);
            return ResultEntity.ok();
        }
        else {
            return ResultEntity.error("信息错误请勾选一条记录");
        }
    }
}
